package com.umeng.common.net;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Environment;
import android.view.animation.Animation;
import android.widget.ImageView;
import com.umeng.common.Log;
import com.umeng.common.b;
import com.umeng.common.b.g;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Stack;
import java.util.WeakHashMap;

public class p
{
  public static boolean a = 0;
  private static final String b = p.class.getName();
  private static final long c = 104857600L;
  private static final long d = 10485760L;
  private static final Map<ImageView, String> e;

  static
  {
    a = false;
    e = Collections.synchronizedMap(new WeakHashMap());
  }

  private static Bitmap a(Bitmap paramBitmap)
  {
    try
    {
      Bitmap localBitmap = Bitmap.createBitmap(paramBitmap.getWidth(), paramBitmap.getHeight(), Bitmap.Config.ARGB_8888);
      Canvas localCanvas = new Canvas(localBitmap);
      Paint localPaint = new Paint();
      Rect localRect = new Rect(0, 0, paramBitmap.getWidth(), paramBitmap.getHeight());
      RectF localRectF = new RectF(localRect);
      localPaint.setAntiAlias(true);
      localCanvas.drawARGB(0, 0, 0, 0);
      localPaint.setColor(-12434878);
      localCanvas.drawRoundRect(localRectF, paramBitmap.getWidth() / 6, paramBitmap.getHeight() / 6, localPaint);
      localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
      localCanvas.drawBitmap(paramBitmap, localRect, localRect, localPaint);
      paramBitmap.recycle();
      return localBitmap;
    }
    catch (OutOfMemoryError localOutOfMemoryError)
    {
      Log.e(b, "Cant`t create round corner bitmap. [OutOfMemoryError] ");
    }
    return null;
  }

  // ERROR //
  public static String a(Context paramContext, String paramString)
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 141	com/umeng/common/b/g:c	(Ljava/lang/String;)Z
    //   4: ifeq +5 -> 9
    //   7: aconst_null
    //   8: areturn
    //   9: new 143	java/lang/StringBuilder
    //   12: dup
    //   13: aload_1
    //   14: invokestatic 146	com/umeng/common/net/p:b	(Ljava/lang/String;)Ljava/lang/String;
    //   17: invokestatic 152	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   20: invokespecial 155	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   23: ldc 157
    //   25: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   28: invokevirtual 164	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   31: astore 4
    //   33: invokestatic 169	com/umeng/common/b:b	()Z
    //   36: ifeq +247 -> 283
    //   39: invokestatic 175	android/os/Environment:getExternalStorageDirectory	()Ljava/io/File;
    //   42: invokevirtual 180	java/io/File:getCanonicalPath	()Ljava/lang/String;
    //   45: astore 5
    //   47: ldc2_w 12
    //   50: lstore 6
    //   52: new 177	java/io/File
    //   55: dup
    //   56: new 143	java/lang/StringBuilder
    //   59: dup
    //   60: aload 5
    //   62: invokestatic 152	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   65: invokespecial 155	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   68: ldc 182
    //   70: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   73: invokevirtual 164	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   76: invokespecial 183	java/io/File:<init>	(Ljava/lang/String;)V
    //   79: astore 8
    //   81: aload 8
    //   83: invokevirtual 186	java/io/File:exists	()Z
    //   86: ifeq +214 -> 300
    //   89: aload 8
    //   91: invokevirtual 189	java/io/File:getCanonicalFile	()Ljava/io/File;
    //   94: invokestatic 192	com/umeng/common/net/p:b	(Ljava/io/File;)J
    //   97: lload 6
    //   99: lcmp
    //   100: ifle +22 -> 122
    //   103: new 194	java/lang/Thread
    //   106: dup
    //   107: new 196	com/umeng/common/net/q
    //   110: dup
    //   111: aload 8
    //   113: invokespecial 199	com/umeng/common/net/q:<init>	(Ljava/io/File;)V
    //   116: invokespecial 202	java/lang/Thread:<init>	(Ljava/lang/Runnable;)V
    //   119: invokevirtual 205	java/lang/Thread:start	()V
    //   122: new 177	java/io/File
    //   125: dup
    //   126: aload 8
    //   128: aload 4
    //   130: invokespecial 208	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   133: astore_3
    //   134: aload_3
    //   135: invokevirtual 211	java/io/File:createNewFile	()Z
    //   138: pop
    //   139: new 213	java/io/FileOutputStream
    //   142: dup
    //   143: aload_3
    //   144: invokespecial 214	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   147: astore 10
    //   149: new 216	java/net/URL
    //   152: dup
    //   153: aload_1
    //   154: invokespecial 217	java/net/URL:<init>	(Ljava/lang/String;)V
    //   157: invokevirtual 221	java/net/URL:openConnection	()Ljava/net/URLConnection;
    //   160: invokevirtual 227	java/net/URLConnection:getContent	()Ljava/lang/Object;
    //   163: checkcast 229	java/io/InputStream
    //   166: astore 11
    //   168: sipush 4096
    //   171: newarray byte
    //   173: astore 12
    //   175: aload 11
    //   177: aload 12
    //   179: invokevirtual 233	java/io/InputStream:read	([B)I
    //   182: istore 13
    //   184: iload 13
    //   186: iconst_m1
    //   187: if_icmpne +219 -> 406
    //   190: aload 10
    //   192: invokevirtual 236	java/io/FileOutputStream:flush	()V
    //   195: aload 11
    //   197: invokevirtual 239	java/io/InputStream:close	()V
    //   200: aload 10
    //   202: invokevirtual 240	java/io/FileOutputStream:close	()V
    //   205: new 177	java/io/File
    //   208: dup
    //   209: aload_3
    //   210: invokevirtual 243	java/io/File:getParent	()Ljava/lang/String;
    //   213: aload_3
    //   214: invokevirtual 244	java/io/File:getName	()Ljava/lang/String;
    //   217: ldc 157
    //   219: ldc 246
    //   221: invokevirtual 250	java/lang/String:replace	(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
    //   224: invokespecial 252	java/io/File:<init>	(Ljava/lang/String;Ljava/lang/String;)V
    //   227: astore 14
    //   229: aload_3
    //   230: aload 14
    //   232: invokevirtual 256	java/io/File:renameTo	(Ljava/io/File;)Z
    //   235: pop
    //   236: getstatic 29	com/umeng/common/net/p:b	Ljava/lang/String;
    //   239: new 143	java/lang/StringBuilder
    //   242: dup
    //   243: ldc_w 258
    //   246: invokespecial 155	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   249: aload_1
    //   250: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   253: ldc_w 260
    //   256: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   259: aload 14
    //   261: invokevirtual 180	java/io/File:getCanonicalPath	()Ljava/lang/String;
    //   264: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   267: invokevirtual 164	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   270: invokestatic 262	com/umeng/common/Log:a	(Ljava/lang/String;Ljava/lang/String;)V
    //   273: aload 14
    //   275: invokevirtual 180	java/io/File:getCanonicalPath	()Ljava/lang/String;
    //   278: astore 16
    //   280: aload 16
    //   282: areturn
    //   283: aload_0
    //   284: invokevirtual 267	android/content/Context:getCacheDir	()Ljava/io/File;
    //   287: invokevirtual 180	java/io/File:getCanonicalPath	()Ljava/lang/String;
    //   290: astore 5
    //   292: ldc2_w 15
    //   295: lstore 6
    //   297: goto -245 -> 52
    //   300: aload 8
    //   302: invokevirtual 270	java/io/File:mkdirs	()Z
    //   305: ifne -183 -> 122
    //   308: getstatic 29	com/umeng/common/net/p:b	Ljava/lang/String;
    //   311: new 143	java/lang/StringBuilder
    //   314: dup
    //   315: ldc_w 272
    //   318: invokespecial 155	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   321: aload 8
    //   323: invokevirtual 275	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   326: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   329: ldc_w 277
    //   332: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   335: invokevirtual 164	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   338: invokestatic 279	com/umeng/common/Log:b	(Ljava/lang/String;Ljava/lang/String;)V
    //   341: goto -219 -> 122
    //   344: astore_2
    //   345: aconst_null
    //   346: astore_3
    //   347: getstatic 29	com/umeng/common/net/p:b	Ljava/lang/String;
    //   350: new 143	java/lang/StringBuilder
    //   353: dup
    //   354: aload_2
    //   355: invokevirtual 283	java/lang/Exception:getStackTrace	()[Ljava/lang/StackTraceElement;
    //   358: invokevirtual 284	java/lang/Object:toString	()Ljava/lang/String;
    //   361: invokestatic 152	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   364: invokespecial 155	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   367: ldc_w 286
    //   370: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   373: getstatic 288	com/umeng/common/b/g:a	Ljava/lang/String;
    //   376: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   379: aload_1
    //   380: invokevirtual 161	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   383: invokevirtual 164	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   386: invokestatic 262	com/umeng/common/Log:a	(Ljava/lang/String;Ljava/lang/String;)V
    //   389: aload_3
    //   390: ifnull +14 -> 404
    //   393: aload_3
    //   394: invokevirtual 186	java/io/File:exists	()Z
    //   397: ifeq +7 -> 404
    //   400: aload_3
    //   401: invokevirtual 291	java/io/File:deleteOnExit	()V
    //   404: aconst_null
    //   405: areturn
    //   406: aload 10
    //   408: aload 12
    //   410: iconst_0
    //   411: iload 13
    //   413: invokevirtual 295	java/io/FileOutputStream:write	([BII)V
    //   416: goto -241 -> 175
    //   419: astore_2
    //   420: goto -73 -> 347
    //
    // Exception table:
    //   from	to	target	type
    //   9	47	344	java/lang/Exception
    //   52	122	344	java/lang/Exception
    //   122	134	344	java/lang/Exception
    //   283	292	344	java/lang/Exception
    //   300	341	344	java/lang/Exception
    //   134	175	419	java/lang/Exception
    //   175	184	419	java/lang/Exception
    //   190	280	419	java/lang/Exception
    //   406	416	419	java/lang/Exception
  }

  public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean)
  {
    a(paramContext, paramImageView, paramString, paramBoolean, null, null, false);
  }

  public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean, a parama)
  {
    a(paramContext, paramImageView, paramString, paramBoolean, parama, null, false);
  }

  public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean, a parama, Animation paramAnimation)
  {
    a(paramContext, paramImageView, paramString, paramBoolean, parama, null, false);
  }

  public static void a(Context paramContext, ImageView paramImageView, String paramString, boolean paramBoolean1, a parama, Animation paramAnimation, boolean paramBoolean2)
  {
    if (paramImageView == null);
    do
    {
      return;
      e.put(paramImageView, paramString);
      try
      {
        File localFile = b(paramContext, paramString);
        if ((localFile == null) || (!(localFile.exists())) || (a))
          break label122;
        if (parama != null)
          parama.a(b.a);
        Drawable localDrawable = c(localFile.getAbsolutePath());
        if (localDrawable == null)
          localFile.delete();
        b(paramContext, paramImageView, localDrawable, paramBoolean1, parama, paramAnimation, paramBoolean2, paramString);
        return;
      }
      catch (Exception localException)
      {
        Log.b(b, "", localException);
      }
    }
    while (parama == null);
    parama.a(o.a.b);
    return;
    label122: new c(paramContext, paramImageView, paramString, b.b, null, paramBoolean1, parama, paramAnimation, paramBoolean2).execute(new Object[0]);
  }

  private static boolean a(ImageView paramImageView, String paramString)
  {
    String str = (String)e.get(paramImageView);
    return ((str != null) && (!(str.equals(paramString))));
  }

  private static long b(File paramFile)
  {
    File[] arrayOfFile;
    long l2;
    int i;
    long l3;
    if ((paramFile == null) || (!(paramFile.exists())) || (!(paramFile.isDirectory())))
    {
      l1 = 0L;
      return l1;
    }
    Stack localStack = new Stack();
    localStack.clear();
    localStack.push(paramFile);
    long l1 = 0L;
    while (true)
    {
      if (!(localStack.isEmpty()));
      arrayOfFile = ((File)localStack.pop()).listFiles();
      l2 = l1;
      i = 0;
      label67: if (i < arrayOfFile.length)
        break;
      l1 = l2;
    }
    if (arrayOfFile[i].isDirectory())
    {
      localStack.push(arrayOfFile[i]);
      l3 = l2;
    }
    while (true)
    {
      ++i;
      l2 = l3;
      break label67:
      l3 = l2 + arrayOfFile[i].length();
    }
  }

  protected static File b(Context paramContext, String paramString)
    throws IOException
  {
    String str1 = b(paramString);
    if (b.b());
    for (String str2 = Environment.getExternalStorageDirectory().getCanonicalPath(); ; str2 = paramContext.getCacheDir().getCanonicalPath())
    {
      File localFile = new File(new File(str2 + "/download/.um"), str1);
      if (!(localFile.exists()))
        break;
      return localFile;
    }
    return null;
  }

  private static String b(String paramString)
  {
    int i = paramString.lastIndexOf(".");
    String str = "";
    if (i >= 0)
      str = paramString.substring(i);
    return g.a(paramString) + str;
  }

  private static void b(Context paramContext, ImageView paramImageView, Drawable paramDrawable, boolean paramBoolean1, a parama, Animation paramAnimation, boolean paramBoolean2, String paramString)
  {
    monitorenter;
    if ((paramBoolean2) && (paramDrawable != null));
    while (true)
    {
      try
      {
        paramDrawable = new BitmapDrawable(a(((BitmapDrawable)paramDrawable).getBitmap()));
        break label203:
        if (parama != null)
          parama.a(o.a.b);
        Log.e(b, "bind drawable failed. drawable [" + paramDrawable + "]  imageView[+" + paramImageView + "+]");
        do
        {
          label87: return;
          if (!(a(paramImageView, paramString)))
            break label157;
        }
        while (parama == null);
      }
      catch (Exception localException)
      {
        Log.b(b, "bind failed", localException);
        if (parama == null);
      }
      finally
      {
        monitorexit;
      }
      if (paramBoolean1)
        label157: paramImageView.setBackgroundDrawable(paramDrawable);
      while (true)
      {
        if (paramAnimation != null)
          paramImageView.startAnimation(paramAnimation);
        if (parama != null);
        parama.a(o.a.a);
        break label87:
        paramImageView.setImageDrawable(paramDrawable);
      }
      label203: if (paramDrawable == null)
        continue;
      if (paramImageView != null)
        continue;
    }
  }

  private static Drawable c(String paramString)
  {
    try
    {
      Drawable localDrawable = Drawable.createFromPath(paramString);
      return localDrawable;
    }
    catch (OutOfMemoryError localOutOfMemoryError)
    {
      Log.e(b, "Resutil fetchImage OutOfMemoryError:" + localOutOfMemoryError.toString());
    }
    return null;
  }

  private static void c(File paramFile)
  {
    File[] arrayOfFile;
    int i;
    if ((paramFile == null) || (!(paramFile.exists())) || (!(paramFile.canWrite())) || (!(paramFile.isDirectory())));
    do
    {
      return;
      arrayOfFile = paramFile.listFiles();
      label33: i = 0;
    }
    while (i >= arrayOfFile.length);
    if (arrayOfFile[i].isDirectory())
      c(arrayOfFile[i]);
    while (true)
    {
      ++i;
      break label33:
      if (new Date().getTime() - arrayOfFile[i].lastModified() <= 1800L)
        continue;
      arrayOfFile[i].delete();
    }
  }

  public static abstract interface a
  {
    public abstract void a(o.a parama);

    public abstract void a(p.b paramb);
  }

  public static enum b
  {
    static
    {
      b[] arrayOfb = new b[2];
      arrayOfb[0] = a;
      arrayOfb[1] = b;
      c = arrayOfb;
    }
  }

  static class c extends AsyncTask<Object, Integer, Drawable>
  {
    private Context a;
    private String b;
    private ImageView c;
    private p.b d;
    private boolean e;
    private p.a f;
    private Animation g;
    private boolean h;
    private File i;

    public c(Context paramContext, ImageView paramImageView, String paramString, p.b paramb, File paramFile, boolean paramBoolean1, p.a parama, Animation paramAnimation, boolean paramBoolean2)
    {
      this.i = paramFile;
      this.a = paramContext;
      this.b = paramString;
      this.f = parama;
      this.d = paramb;
      this.e = paramBoolean1;
      this.g = paramAnimation;
      this.c = paramImageView;
      this.h = paramBoolean2;
    }

    protected Drawable a(Object[] paramArrayOfObject)
    {
      if (p.a);
      try
      {
        Thread.sleep(3000L);
        label12: if ((this.i == null) || (!(this.i.exists())))
          break label75;
        Drawable localDrawable2 = p.a(this.i.getAbsolutePath());
        if (localDrawable2 == null)
          this.i.delete();
        Log.c(p.a(), "get drawable from cacheFile.");
        label75: return localDrawable2;
      }
      catch (InterruptedException localInterruptedException)
      {
        localInterruptedException.printStackTrace();
        break label12:
        try
        {
          p.a(this.a, this.b);
          File localFile = p.b(this.a, this.b);
          if ((localFile != null) && (localFile.exists()))
          {
            localDrawable1 = p.a(localFile.getAbsolutePath());
            Log.c(p.a(), "get drawable from net else file.");
            return localDrawable1;
          }
        }
        catch (Exception localException)
        {
          Log.e(p.a(), localException.toString(), localException);
          return null;
        }
        Drawable localDrawable1 = null;
      }
    }

    protected void a(Drawable paramDrawable)
    {
      p.a(this.a, this.c, paramDrawable, this.e, this.f, this.g, this.h, this.b);
    }

    protected void onPreExecute()
    {
      super.onPreExecute();
      if (this.f == null)
        return;
      this.f.a(this.d);
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     com.umeng.common.net.p
 * JD-Core Version:    0.5.2
 */